package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdRuleBaseVO;
import com.yunxi.otd.service.OtdRuleBaseDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 生产规则库 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-10-09
 */
@RestController
@RequestMapping("/admin/rule")
@Api(tags = "OTD:otdrulebase", description = "生产规则库接口")
public class OtdRuleBaseController {

    private static final Logger logger = LoggerFactory.getLogger(OtdRuleBaseController.class);

    @Autowired
    OtdRuleBaseDubboService otdRuleBaseDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询生产规则库分页")
    public ApiResult page(OtdRuleBaseVO otdRuleBaseVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(otdRuleBaseDubboService.findPageByVO(otdRuleBaseVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询所有")
    public ApiResult list(OtdRuleBaseVO otdRuleBaseVO) throws Exception {
        return ResponseUtil.ok(otdRuleBaseDubboService.listByVo(otdRuleBaseVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个生产规则库")
    public ApiResult load(@RequestParam String id) throws Exception {
        return ResponseUtil.ok(otdRuleBaseDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存生产规则库信息")
    public ApiResult save(@RequestBody OtdRuleBaseVO otdRuleBaseVO) throws Exception {
        return otdRuleBaseDubboService.saveOrUpdate(otdRuleBaseVO);
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除生产规则库")
    public ApiResult del(@RequestBody List<OtdRuleBaseVO> otdRuleBaseVOList) throws Exception {
        otdRuleBaseDubboService.removeByListVo(otdRuleBaseVOList);
        return ResponseUtil.ok("success");
    }
}
